<?php 
namespace App\Http\Common;

use Illuminate\Http\Request;

use DB;
use Route;
use Session;
/**
 * 操作日志服务
 * Class LogService
 * @package service
 * @author Anyon <zoujingli@qq.com>
 * @date 2017/03/24 13:25
 */
class LogService {

    /**
     * 获取数据操作对象
     * @return \think\db\Query
     */
    protected static function db() {
        return DB::table('system_log');
    }

    /**
     * 写入操作日志
     * @param string $action
     * @param string $content
     * @return bool
     */
    public static function write($req, $action = '行为', $content = "内容描述") {
        $data = ['ip' => $req->ip(), 'node' => Route::current()->getActionName(), 'username' => Session::get('user')->username . '', 'action' => $action, 'content' => $content];
        return self::db()->insert($data) !== false;
    }
}